<?php
/**
	*****************************************************************
	* 联系QQ：290802026/1073744729									*
	* QQ  群：429403774，提供技术交流等								*
	* 版  本：V2.3.1												*
	* 开发者：RockOA研发中心/雨中磐石工作室							*
	* 邮  箱：admin@rockoa.com										*
	* 网  址：http://www.rockoa.com/								*
	* 说  明: 核心代码不要修改哦									*
	* 备  注: 未经允许不得商业出售，代码欢迎参考纠正				*
	* 修改时: 2016-05-08 18:17:21									*	
	*****************************************************************
*/
 class jmChajian extends Chajian{private $keystr = 'abcdefghijklmnopqrstuvwxyz';private $jmsstr = '';public  $rocktokenarr = array();protected function initChajian(){$this->initJm();}public function initJm(){$this->jmsstr = getconfig('randkey');$this->setRandkey($this->jmsstr);$this->getkeyshow();}public function setRandkey($str){$this->jmsstr = $str;if(strlen($this->jmsstr)<26)$this->jmsstr = $this->keystr;$this->getrocktoken();}public function getRandkey(){$str = $this->keystr;$s  = '';$len = strlen($str);$j  = $len-1;for($i=0; $i<$len; $i++){$r = rand(0, $j);$zm= substr($str, $r, 1);$s.= $zm;$str = str_replace($zm,'',$str);$j--;}return $s;}public function getint($str){$len = strlen($str);$oi  = 0;for($i=0; $i<$len; $i++){$l = substr($str,$i,1);$j = ord($l)-90;$oi+=$j;}if($oi<0)$oi=0-$oi;return $oi;}private function getrandstr($oi, $str=''){if($str=='')$str=$this->keystr;if($oi>100)$oi=100;$len = strlen($str);$qs  = 6;$s1  = substr($str, 0, $qs);$s2 = substr($str, $qs, $qs);$s3  = substr($str, $qs*2, $len-$qs*2);$s   = $s3.$s2.$s1;if($oi>0)$s=$this->getrandstr($oi-1, $s);return $s;}public function getkeyshow(){$str = '~!@#$%^&*()_+{}[];"<>?:-=.';$len = strlen($this->jmsstr);$s  = '';for($i=0;$i<$len;$i++){$l = substr($this->jmsstr,$i,1);$j = ord($l)-97;$s.= substr($str,$j,1);}return $s;}public function base64encode($str){if($this->rock->isempt($str))return '';$str= base64_encode($str);$str= str_replace(array('+', '/', '='), array('!', '.', ':'), $str);return $str;}public function base64decode($str){if($this->rock->isempt($str))return '';$str= str_replace(array('!', '.', ':'), array('+', '/', '='), $str);$str= base64_decode($str);return $str;}private function _getss($lx){$st = '';if(is_numeric($lx)&&$lx>0){$st = $this->getrandstr($lx);}else if(is_string($lx)){if(strlen($lx)==26)$st=lx;}return $st;}public function encrypt($str, $lx=''){$st = $this->_getss($lx);$s= $this->base64encode($str);$s= $this->encrypts($s, $st);return $s;}public function uncrypt($str, $lx=''){$st = $this->_getss($lx);$s= $this->uncrypts($str, $st);$s= $this->base64decode($s);return $s;}public function encrypts($str, $a=''){if($a=='')$a = $this->jmsstr;$nstr= '';if($this->rock->isempt($str)) return $nstr;$len= strlen($str);$t= rand(1, 14);if($t == 10)$t++;for($i=0; $i<$len; $i++){$nstr.='0';$sta= substr($str,$i,1);$orstr= ''.ord($sta).'';$ile= strlen($orstr);for($j=0; $j<$ile; $j++){$oi= (int)substr($orstr,$j,1)+$t;$nstr.= substr($a,$oi,1);}}if($nstr != ''){$nstr = substr($nstr,1);$nstr.= '0'.$t.'';}return $nstr;}public function uncrypts($str, $a1=''){$nstr= '';if($this->rock->isempt($str)) return $nstr;if($a1=='')$a1= $this->jmsstr;$a= array();for($i=0; $i<strlen($a1); $i++)$a[substr($a1, $i, 1)] = ''.$i.'';$na= explode('0', $str);$len= count($na);$r= (int)$na[$len-1];for($i=0; $i<$len-1; $i++){$st= $na[$i];$sl = strlen($st);$sa= '';for($j=0; $j<$sl; $j++){$ha= substr($st,$j,1);if(isset($a[$ha]))$ha = $a[$ha] - $r;$sa.=$ha;}$sa= (int)$sa;$nstr.=chr($sa);}return $nstr;}public function getrocktoken(){$toke = $this->rock->get('rocktoken');$str = $this->uncrypt($toke);if($toke!='' && !$this->contain($str,'&'))exit('sorry,not found!');$arr= array('m'=>'index','a'=>'default','d'=>'');if($str){$a = explode('&', $str);foreach($a as $a1){$a2 = explode('=', $a1);$arr[$a2[0]] = $a2[1];}}$this->rocktokenarr = $arr;return $arr;}public function gettoken($na, $dev=''){$s = $dev;if(isset($this->rocktokenarr[$na])){$s = $this->rocktokenarr[$na];}else{$s = $this->rock->get($na, $dev);}return $s;}public function strrocktoken($a=array()){$s = '';foreach($a as $k=>$v){$s .='&'.$k.'='.$v.'';}if($s!=''){$s = $this->encrypt(substr($s, 1));}return $s;}}